#include <REGX52.H>
#include "LCD1602.H"
#include "AT24C02.H"
#include "I2C.H"
#include "Delay.H"
#include "Key.H"
	
void main()
{
	
	unsigned char KeyNum  = 5;
	unsigned int Num = 0;

	LCD_Init();

	LCD_ShowNum(1,1,0,5);
	
	while(1)
	{
		KeyNum = Key();
		
		if(KeyNum == 0)
		{
			Num++;
			LCD_ShowNum(1,1,Num,5);
		}
		
		if(KeyNum == 1)
		{
			Num--;
			LCD_ShowNum(1,1,Num,5);
		}
		
		if(KeyNum == 2)
		{
			AT24C02_Write(0,Num%256);//写入16位数据
			Delay(5);
			AT24C02_Write(1,Num/256);
			Delay(5);
			
			LCD_ShowString(2,1,"Write OK");
		}
		
		if(KeyNum == 3)
		{
			
			Num  = AT24C02_Read(0);
			Num |= AT24C02_Read(1) << 8;
			
			LCD_ShowNum(1,1,Num,5);
			
			LCD_ShowString(2,1,"Read  OK");
			
		}
		
	}
	
}